/*
 * @Author: fishroom
 * @Date: 2022-09-28 11:26:55
 * @LastEditTime: 2022-10-28 15:50:18
 * @FilePath: \koa\app\middleware\AccessLogMiddleWare.ts
 */
import { Context, Next } from "koa";
import { accessLogger } from "../logger";
function getDate() {
  return `${new Date().toLocaleDateString()}---${new Date().toLocaleTimeString("chinese", {
    hour12: false,
  })}`;
}

function AccessLogMiddleWare(ctx: Context, next: Next) {
  const logStr = `date:${getDate()} | path:${ctx.path} | method:${ctx.method} | ua:${
    ctx.headers["user-agent"]
  }`;
  accessLogger.info(logStr);

  return next();
}
export default AccessLogMiddleWare;
